<?php
/**
* 关注功能的模型
*/
class ModelGuanzhu extends GetLoad
{
	
	public function getguanzhu($concerned_id){
		$reluse=$this->SQLquery("SELECT * from noticer where concerned_id=".$concerned_id);
		$this->SQLcun("UPDATE noticer SET chakan='0' where concerned_id='".$concerned_id."'");
		return $reluse;

	}

	public function getwoguanzhu($noticer_id){
		$reluse=$this->SQLquery("SELECT * from noticer where noticer_id=".$noticer_id);
		return $reluse;

	}

	public function getname($name_id){
		//echo $name_id;
		$reluse=$this->SQLquery("SELECT * from name where name_id=".$name_id);
		//var_dump($reluse);
		return $reluse[0];

	}

	public function panduan($name_id,$name_id2){
		//echo $name_id;
		$reluse=$this->SQLquery("SELECT * from noticer where concerned_id=".$name_id2." and noticer_id=".$name_id);
//		var_dump($reluse);
		if($reluse){
			return "取消互关";
		}else{
			return "关注";
		}

	}

	public function panduan2($name_id,$name_id2){
		//echo $name_id;
		$reluse=$this->SQLquery("SELECT * from noticer where concerned_id=".$name_id2." and noticer_id=".$name_id);
		//var_dump($reluse);
		if($reluse){
			return "./index.php?route=Controller/guanzhu/ControllerGuanzhu/quxiaoguanzhu&=".$reluse[0]['id'];
		}else{
			return "./index.php?route=Controller/guanzhu/ControllerGuanzhu/guanzhu&=".$name_id2;
		}

	}


	public function quxiaoguanzhu($id){//取消关注函数

		$rusule=$this->SQLquery("SELECT * FROM noticer where id=".$id);


		if($rusule[0]['noticer_id'] == $this->yanzheng()){
			$this->SQLcun("DELETE FROM noticer WHERE id = ".$id);
			//echo "DELETE FROM noticer WHERE id = ".$id;
		}
		

		header("Location: ./index.php?route=Controller/guanzhu/ControllerGuanzhu/getwoguanzhu&=".$rusule[0]['noticer_id']); 

	}


	public function yanzheng(){

		$rusule=$this->SQLquery("SELECT * FROM name where name='".$_COOKIE["name"]."' AND password='".$_COOKIE["password"]."'");



		return $rusule[0]["name_id"];
	}

	public function guanzhu($id){

		$rusule=$this->SQLquery("SELECT * FROM name where name='".$_COOKIE["name"]."' AND password='".$_COOKIE["password"]."'");

		$this->SQLcun("INSERT INTO noticer (concerned_id,noticer_id,chakan) VALUES (".$id[0].",".$rusule[0]['name_id'].",1)"); 

		

		header("Location: ./index.php?route=Controller/guanzhu/ControllerGuanzhu/getwoguanzhu&=".$rusule[0]['name_id']); 


	}

}